package com.plusone.toolset;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Mailer {

	/**
	 * 
	 * @param sender
	 * @param senderName
	 * @param recipients
	 * @param subject
	 * @param messageBody
	 */
	public static void Send(String sender, String senderName,
			List<String> recipients, String subject, String messageBody) {

		Properties mailProperties = new Properties();
		Session mailSession = Session.getDefaultInstance(mailProperties, null);

		Message message = new MimeMessage(mailSession);
		try {
			message.setFrom(new InternetAddress(sender, senderName));
			for (String recipient : recipients) {
				message.addRecipient(Message.RecipientType.TO,
						new InternetAddress(recipient));
			}
			message.setSubject(subject);
			message.setContent(messageBody, "text/html; charset=ISO-8859-1");

			Transport.send(message);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
